package gold.digger;

import gold.utils.InputUtil;

/**
 * Created by fanzhenyu02 on 2021/12/10.
 * common problem solver template.
 */
public class LC2043 {
    public long startExecuteTime = System.currentTimeMillis();


    class Bank {

        long[] balance;

        public Bank(long[] balance) {
            this.balance = new long[balance.length];
            for (int i = 0; i < balance.length; i++) {
                this.balance[i] = balance[i];
            }
        }

        public boolean transfer(int account1, int account2, long money) {
            if (checkBoundaryFail(account1)) return false;
            if (checkBoundaryFail(account2)) return false;
            if (balance[account1 - 1] < money) return false;
            balance[account1 - 1] -= money;
            balance[account2 - 1] += money;
            return true;
        }

        public boolean deposit(int account, long money) {
            if (checkBoundaryFail(account)) return false;
            balance[account - 1] += money;
            return true;
        }

        public boolean withdraw(int account, long money) {
            if (checkBoundaryFail(account)) return false;
            if (balance[account - 1] < money) return false;
            balance[account - 1] -= money;
            return true;
        }

        public boolean checkBoundaryFail(int acc) {
            return (acc > balance.length || acc < 1);
        }
    }

    public void run() {
        int[] arr = InputUtil.toIntegerArray("[1,2,3]");
        System.out.println(new Bank(new long[]{}).toString());
    }

    public static void main(String[] args) throws Exception {
        LC2043 an = new LC2043();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
